#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED

#include "../utils/sc_car_def_manager.h"
#include "../utils/sc_car_def_loader.h"
#include "src/utils/settings.h"
#include "raycastvehicle.h"
#include "entity.h"

enum Inputtype
{
	KEYBOARD = 0,
	JOYSTICK,
	MOUSE
};

class Car : public Entity
{
	public:
		Car(unsigned int mplayerid, btTransform& transform, boost::shared_ptr<btDynamicsWorld> ownerWorld);
		virtual ~Car();
		
		virtual void		draw();
		virtual void		updatePosition();
// 		virtual void		copyPosition();

		void upload()
		{			
			m_wheelModel->upload();
			m_carModel->upload();
		}

		boost::shared_ptr<bRaycastVehicle> m_vehicle;
		boost::shared_ptr<btRigidBody> m_carChassis;
		
		float	m_throttlesum;
		float	m_brakingsum;
		
		float	gEngineForce;
		float	gBreakingForce;
		float	gVehicleSteering;
		float	gLinVehicleSteering;
		void	setExpSteering();
		float	maxEngineForce;//this should be engine/velocity dependent
		float	maxBreakingForce;
		float	defaultBreakingForce;

		float	steeringIncrement;
		float	steeringClamp;
		float	steeringExponentiality;

		void	applyForcesClient( float reltime, Inputtype input );
		void	applyForces( float reltime, Inputtype input );

		bool	m_lockaccel;
		
		unsigned int playerid;

		// car discrete motion handles // FIXME get rid of these?
			float m_throttle;
// 			bool m_forw;
// 			bool m_back;
			bool m_left;
			bool m_right;
// 			bool m_handbrake;
			float m_braking;

		bool m_drawChassis;

		boost::shared_ptr<Model>	m_carModel;
		boost::shared_ptr<Model>	m_wheelModel;

	private:
		struct DrawWheel_Info
		{
			btScalar wheelbuffers[16];
			btScalar drawwheelbuffers[16];
		};

		const unsigned int*		setting_joystick;

		Settings*		settings;
		bRaycastVehicle::btVehicleTuning m_tuning;
		boost::shared_ptr<btVehicleRaycaster> m_vehicleRayCaster;
		btCollisionShape* m_wheelShape;
		const ScCarDef* carDef;

		vector<DrawWheel_Info>	drawwheel_info;
		
		void createWheelPair( unsigned int wheelpairindex, const ScChassisDef& chassisattachment );
// 		void createWheel( const ScWheelAttachment& attachment );

};

#endif
